package com.kk.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.sql.Date;
import java.util.Map;

public class JwtUtils {
    private static String key = "adult";
    private static Long keyTime = 60*1000L;
    public static String getJwt(Map<String, Object> claims) {


        String adult = Jwts.builder().signWith(SignatureAlgorithm.HS256, key)
                .setClaims(claims)//给定的数据
                .setExpiration(new Date(System.currentTimeMillis() + keyTime))
                .compact();//生成令牌
        return adult;

    }

    public static Claims parseJwt(String jwt) {
        Claims adult = Jwts.parser().setSigningKey(key).parseClaimsJws(jwt)
                .getBody();
        return adult;
    }
}
